package planeGame;

import java.awt.*;
import java.awt.event.KeyEvent;

public class Plane extends GameObject{
    boolean left,right,down,up;
    boolean live=true;
    //重写
    public void drowSelf(Graphics g){
        if(live){
            g.drawImage(img,(int)x,(int)y,null);
            if(left){
                x-=speed;//子类连方法，和变量都继承了
            }
            if(right){
                x+=speed;
            }
            if(up){
                y-=speed;
            }
            if(down){
                y+=speed;
            }
        }else {

        }

    }

    public Plane(Image img, double x, double y) {//接收传进来的参数
        super(img, x, y);
        //获取飞机的宽高，碰撞检测可以获得飞机的宽高
        this.width = img.getWidth(null);
        this.height = img.getHeight(null);
    }

    //摁下上下左右增加相应方向
    public void addDirection(KeyEvent event){
        switch (event.getKeyCode()) {
            case KeyEvent.VK_LEFT://vk提供的虚拟键
                left = true;
                break;
            case KeyEvent.VK_UP:
                up = true;
                break;
            case KeyEvent.VK_RIGHT:
                right = true;
                break;
            case KeyEvent.VK_DOWN:
                down = true;
                break;
        }
    }

    //摁下上下左右取消相应方向
    public void minusDirection(KeyEvent event){
        switch (event.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                left = false;
                break;
            case KeyEvent.VK_UP:
                up = false;
                break;
            case KeyEvent.VK_RIGHT:
                right = false;
                break;
            case KeyEvent.VK_DOWN:
                down = false;
                break;
        }
    }
}
